package com.yjz.media.study.base;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

/**
 * 作用 : 基类
 * 作者 : yjz
 * 时间 : 2023/11/7 17:06
 */
public abstract class BaseActivity<T extends ViewDataBinding> extends AppCompatActivity {

    public T mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getLayoutId() > 0) {
            before(savedInstanceState);
            mBinding = DataBindingUtil.setContentView(this, getLayoutId());
            initArgs();
            initView();
            initData();
        }
    }

    public void initArgs() {

    }

    public void initData() {

    }

    public void initView() {

    }

    public void before(Bundle savedInstanceState) {

    }

    public abstract int getLayoutId();

    public void startActivity(Class<?> clazz) {
        Intent intent = new Intent(this, clazz);
        startActivity(intent);
    }

    public void showMessageDialog(String title, String message, DialogInterface.OnClickListener onClickListener) {
        new AlertDialog.Builder(this)
                .setTitle(title)
                .setMessage(message)
                .setNegativeButton("确定", onClickListener)
                .setCancelable(false)
                .create()
                .show();
    }
}
